/*
 * \brief  Pistachio-specific sleep implementation
 * \author Julian Stecklina
 * \date   2008-03-19
 */

/*
 * Copyright (C) 2008-2009 Julian Stecklina
 * Genode Labs, Feske & Helmuth Systementwicklung GbR
 *
 * This file is part of the Genode OS framework, which is distributed
 * under the terms of the GNU General Public License version 2.
 */

#include <base/blocking.h>

namespace Pistachio {
#include <l4/ipc.h>
}

#include "timer_session_component.h"


void Timer::Session_component::msleep(unsigned ms)
{
	using namespace Pistachio;

	/*
	 * See 'base/src/base/lock' for a description of how the
	 * user-defined handle is used.
	 */
	enum { MAGIC_USER_DEFINED_HANDLE = 13 };
	L4_Set_UserDefinedHandle(MAGIC_USER_DEFINED_HANDLE);

	L4_Sleep(L4_TimePeriod(ms * 1000));

	/* check if sleep was canceled */
	if (L4_UserDefinedHandle() != MAGIC_USER_DEFINED_HANDLE)
		throw Genode::Blocking_canceled();
}
